$(document).ready(function() {
var vals = setupHeader();
setupModal(vals);

setup();
setupTheatre();

$(window)
.scroll(toggleScroll)
.resize(toggleResize);

$('[tabindex]')
.live('keypress click', openLink);

$('input[type="email"]:not([value=""])')
.live('change focusout', verifyEmail);

$('input:password:not([value=""])')
.live('focusout', verifyPword);

$('input:text:not([value=""]), textarea:not([value=""])')
.live('focusout', verifyText);

$('textarea:not(.read)')
.live('keydown focusin focusout change paste', procTextarea);

$('button:reset, .reset')
.live('click', resetForm);

$('input, textarea, select')
.live('keydown', untapField);

$('select.readonly')
.live('click change', selectReadonly);

$('[readonly]')
.live('focusin', function() { $(this).blur(); });

$('[type="number"], .number')
.live('keydown', procNumber);

$('[data-tool]:not(.lock)')
.live('focusin focusout mouseenter mouseleave', procTool);

$('.tip')
.live('focusin focusout mouseenter mouseleave', procTip);

$('.tipMore, .tipLess')
.live('click', procMoreTip);

$('.tip.retain')
.live('click', fadeOut);

$('[data-for]')
.live('click', focusField);

$('.modal-accept, .modal-reject')
.live('click', function() { $(this).closest('.area').showModal(false); });

$('.conf-accept, .conf-reject')
.live('click', function() { $(this).closest('.area').notifyModal(false, false, false); });

$('.reset, .cancel')
.live('click', procCancel);

$('.clear')
.live('click', clearAll);

$('.clearone')
.live('click', clearField);

$('#htitle')
.live('click', gotoArea);

$('.peel:not(div, .locked)')
.live('click', {action: 'fade'}, peelObject);

$('div.peel:not(.locked)')
.live('click keypress', peelObject)

$('button.expand.all')
.live('click', expandAll);

$('button.collapse.all')
.live('click', collapseAll);

$('.halt')
.live('click focusin', function(e) { e.preventDefault(); return false; });

$('.close-content')
.live('click', function() { $('.heading', $(this).closest('.area')).trigger('click'); });

$('.modal:not(.lock, .notif)')
.live('click', bringToTop);

$('[data-href]:not(.lock)')
.live('click', gotoHref);

$('[data-modal]')
.live('click', showThisModal);

$('[data-doc]')
.live('click', openFile);

$('[data-guess]')
.live('keyup keydown click focusout', guessQuery);

$('div.guess')
.live('click', procGuess);

$('div.guesses')
.live('mouseenter mouseover focusin', showGuesses);

$('#coat, #mask')
.live('click mouseenter', procCoat);

$('#top')
.live('click', gotoTop);

$('select.navi')
.live('change', toggleSelect);

$('#head [type="search"]')
.live('focusin focusout', procHeadSearch);

$('.guess a')
.live('click', function(e) { e.preventDefault(); });

$('.ui-button.disabled')
.live('click', halt);

///////////////////////////////////////////////////////////////////////////

$('#form-search-index')
.live('submit', searchMicroIndex);

$('.form-signin, #form-search-index')
.live('submit', verifyFormIndex);

$('#form-create, #form-create-json')
.live('submit', create);

$('#form-signup')
.live('submit', signup);

$('#lnkChangeMyPword')
.live('click', {user: true}, showChangePword);

$('#form-myacct-verify')
.live('submit', submitMyAcct);

$('#form-search')
.live('keypress', procSearch);

$('#form-extdsearch')
.live('submit', procExtSearch);

$('select.categ')
.live('change', changeCateg);

$('.micro:text, .proj:text, .img:text, .doc:text, .micro:file, .edtr:text, .sec:text, .srce:text, .loc:text, .rsrc:text, .link:text, .file:file, .coed:text, .syno:text, .comn:text, .taxon:text, .host:text, .srce:text')
.live('keypress focusout', verifyItem);

$('button.edit, .div-header.active.cancel')
.live('click', editSettings);

//////////////////////////////////////////////////////////////////////////////////////

$('.create .modal-reject, .create .reset')
.live('click', cancelCreate);

$('.heading')
.live('click keypress', displayItem);

$('.knob')
.live('mouseenter mouseleave', procKnob);

$('.knob')
.live('click keypress', accordItem);

$('.cbxImg, .cbxDoc')
.live('click', setDeleteFile);

$('button.append')
.live('click', appendItem);

$('.cancel-append')
.live('click', cancelAppend);

$('button.remove')
.live('click', removeItem);

$('button.undo')
.live('click', undoRemoveItem);

$('.fetch.micro')
.live('click', fetchMicro);

$('.fetch.proj')
.live('click', fetchProj);

$('.fetch.img')
.live('click', fetchImg);

$('.fetch.doc')
.live('click', fetchDoc);

$('.fetch.loc')
.live('click', fetchLoc);

$('.fetch.rsrc, .fetch.link')
.live('click', fetchRsrc);

$('.details.dial')
.live('click', showDetails);

$('.navi-details')
.live('click', showSearchDetails);

$('button.delete:not(.acct)')
.live('click', confDeleteItem);

$('button.recover')
.live('click', confRecoverItem);

$('button.edit.edtr.dial')
.live('click', editEdtr);

////////////////////////////////////////////////////////////
// Account

$('.lnkChangePword')
.live('click', {user: false}, showChangePword);

$('.acct.area .delete')
.live('click', setDeleteAcct);

$('.acct.area .reset')
.live('click', resetAcct);

$('form.acct')
.live('submit', submitAcct);

$('button.reject-appn')
.live('click', rejectAppn);

///////////////////////////////////////////////////////////////////////
// Microorganism

$('.micro.area form.micro:not(.create)')
.live('submit', submitMicro);

$('select[name="pref"]')
.live('change', selectPref);

$('.categ.micro')
.live('change', procMicroCateg);

$('.view-taxon')
.live('click', viewTaxon);

$('.view-taxon-in')
.live('click', viewTaxonIn);

$('#search-taxon')
.live('submit', searchTaxon);

$('.edit-taxon')
.live('click', editTaxon);

$('.cancel-edit-taxon')
.live('click', cancelEditTaxon);

$('select[name="rnk"]')
.live('change', changeTaxonRank);

$('.distn.dial')
.live('click', viewDistnMap);

$('[name="input[]"]:file, [name="input[multi][]"]:file')
.live('change', showFilelist);

$('img.test')
.live('click', showMask);

$('.rem-file')
.live('click', removeFile);

////////////////////////////////////////////////////////////////////
// Project

$('.proj.area button.append-sec')
.live('click', appendSec);

$('.proj.area button.append-srce')
.live('click', appendSrce);

$('img.file:not(.default, .locked)')
.live('mouseenter mouseleave', setCtrlImg);

$('[name="pic"]')
.live('click', selectImgAsDefault);

$('.ctrl-img')
.live('mouseleave', fadeOut);

$('.rmv-img:checkbox')
.live('click', procRemoveImg);

$('.def-img:checkbox')
.live('click', setDefaultImg);

$('.proj.area form.proj:not(.create)')
.live('submit', submitProj);

///////////////////////////////////////////////////////////////////
// Image

$('.img.area form.img:not(.create)')
.live('submit', submitImg);

$('.clip-reject, .bubble-reject')
.live('click', hideBubbleClip);

$('img.stage')
.live('click keypress', stageImg);

$('.open.img.dial')
.live('click', openImg);

$('button.mark')
.live('click', setImgMark);

$('input:file.upload')
.live('change', upload);

$('button.img-home')
.live('click', setHomeImg);

$('img.mark')
.live('click', showMask);

$('.thumb.mark')
.live('mouseenter mouseleave', zoomInMark)
.live('click', focusMark);

$('.bubble.area a.thumb')
.live('click', focusMark);

$('.bubble.modal')
.live('mouseenter mouseleave', procBubble);

$('.toggle-form')
.live('change', toggleClipForm);

$('.toggle-thumb-opt')
.live('change', toggleMarkOption);

$('button.handle')
.live('click', showBubbleMarks);

$('#form-mark-img')
.live('submit', markImg);

$('form.mark-add.micro')
.live('submit', addMarkMicro);

$('form.mark-add.img')
.live('submit', addMarkImg);

$('form.mark-add.rsrc')
.live('submit', addMarkRsrc);

$('button.expand.marks')
.live('click', expandMark);

$('button.collapse.marks')
.live('click', collapseMark);

$('button.add-handle')
.live('click', showAddlBlockDetails);

$('.edit-mark .mark-edit')
.live('click', setEditMark);

$('.mark-remove')
.live('click', confRemoveMark);

$('form.edit-mark')
.live('submit', editMark);

///////////////////////////////////////////////////////////////////
// Documents

$('.doc.area form.doc:not(.create)')
.live('submit', submitDoc);

///////////////////////////////////////////////////////////////////
// Locations

$('a.map')
.live('click', viewMap);

$('#create.loc')
.live('click', setCreateLoc);

$('.loc.area form.loc:not(.create)')
.live('submit', submitLoc);

$('a.open.loc')
.live('click', openLocInline);

$('div.open.loc')
.live('click', openLocInline);

/////////////////////////////////////////////////////////////////////
// Resources

$('button.share')
.live('click', openShareRsrc);

$('form.share.rsrc')
.live('submit', shareRsrc);

$('.rsrc.area form.rsrc:not(.create)')
.live('submit', submitRsrc);

/////////////////////////////////////////////////////////////////////
// Applications

$('.appn.area form.appn:not(.create)')
.live('submit', submitAppn);

////////////////////////////////////////////////////////////////////

$('.theatre a:not(.thumb)')
.live('click', restrictContent);

$('#sr-current.active')
.live('mouseenter mouseover', showIndexContainer);

$('#sr-container')
.live('mouseenter mouseleave', procIndexContainer);

$('.sr-item')
.live('click', changeScene);
	
var end = getTime();
var currEnd = formatTime(end.slice(1));

var diff = getTimeDiff(start[0], end[0]);
var currDiff = formatTime(diff);

console.log('page e: '+currEnd);
console.log('page s: '+currStart);
console.log('page d: '+currDiff);

console.log('--------------------------------------------------');

if(getCookie('timeValue').length && getCookie('timeObject')+''.length) {
	var jumpStart = getCookie('timeValue');
	var jumpObject = new Date(parseInt(getCookie('timeObject')));
	var jumpDiff = formatTime(getTimeDiff(jumpObject,end[0]));
	
	console.log('load e: '+currEnd);
	console.log('load s: '+jumpStart);
	console.log('load d: '+jumpDiff);
	
	document.cookie = 'timeObject=';
	document.cookie = 'timeValue=';
}

window.onbeforeunload = function() {
	var val = getTime();
	
	setCookie('timeObject', val[0].getTime());
	setCookie('timeValue', formatTime(val.splice(1)));
}
});

var start = getTime();
var currStart = formatTime(start.slice(1));
























